<template>
  <!-- <div id="echartsView" class="className"/> -->
  <div>
    <div id="studentcor" style="width:100%; height:500px"></div>
  </div>
</template>

<script>
import echarts from 'echarts'

export default {
  props: {
    finishNum: {
      type: Number,
      default() {
        return 0
      }
    },
    unStartNum: {
      type: Number,
      default() {
        return 0
      }
    },
    onGoingNum: {
      type: Number,
      default() {
        return 0
      }
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById('studentcor'))
      this.chart.setOption({
        title: {
          text: '学习课程',
          x: 'left'
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: 'vertical',
          x: 'right'
        },
        series: [
          {
            name: '学习状态',
            type: 'pie',
            selectedMode: 'single',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
              {
                value: this.unStartNum,
                name: '未开始',
                itemStyle: {
                  color: '#A9A9A9'
                }
              },
              {
                value: this.onGoingNum,
                name: '进行中',
                selected: true,
                itemStyle: {
                  color: '#1E90FF'
                }
              },
              {
                value: this.finishNum,
                name: '已完成',
                itemStyle: {
                  color: '#00FF00'
                }
              }
            ]
            // itemStyle: {
            //   normal: {
            //     color: '#1E90FF',
            //     borderWidth: 0.5,
            //     borderColor: '#ffffff'
            //   },
            //   emphasis: {
            //     color: '#00FA9A',
            //     shadowBlur: 10,
            //     shadowOffsetX: 0,
            //     shadowColor: 'rgba(0, 0, 0, 0.5)'
            //   }
            // }
          }
        ]
      })
    }
  }
}
</script>
